// 跳跃游戏

package Leetcode;

class soltuion_055 {
    public boolean canJump(int[] nums) {
        boolean[] dp = new boolean[nums.length];
        dp[0] = true;
        for (int i = 1; i < nums.length; i++) {
            int j = 0;
            for (; j < i; j++)
                if (nums[j] + j >= i) {
                    dp[i] = true;
                    break;
                }
            if (j == i)
                return false;
        }
        return true;
    }
}

public class Solution055 {
    public boolean canJump(int[] nums) {
        int maxLength = 0; // 最远可以到达的位置
        for (int i = 0; i < nums.length; i++) {
            if (i > maxLength)
                break;
            maxLength = Math.max(maxLength, i + nums[i]);
            if (maxLength >= nums.length - 1)
                return true;
        }
        return false;
    }
}
